package com.yiji.fintech.musfinance.common.strategy.base;

import com.yiji.fintech.musfinance.base.facade.GatewayOrderFacade;
import com.yiji.fintech.musfinance.base.facade.GatewayResultFacade;
import com.yiji.fintech.musfinance.center.base.result.ResultFacade;
import com.yiji.fintech.musfinance.common.domain.base.BaseDomain;
import com.yiji.fintech.musfinance.common.utils.TransStatusConverter;

/**
 * 发送网关context
 * Created by ouwen@yiji.com} on 2017/8/9.
 */
public abstract class AbstractSendGateWayBaseStrategy {
    protected GatewayOrderFacade orderGateWay;
    protected GatewayResultFacade resultGateWay;
    public void doExcute(BaseDomain domain, ResultFacade result){
        orderGateWay = converter(domain);//domain转换网关order
        resultGateWay = send(domain);//发送网关
        converter2TransStatus(domain);//网关交易结果转换调度中TransStatus
        result(domain,result);//结果处理
    }
    private void converter2TransStatus(BaseDomain domain){
        TransStatusConverter.converter(domain,resultGateWay);
    }

    /**
     * 业务另外domain转换网关order
     * @param domain
     * @return
     */
    protected abstract GatewayOrderFacade converter(BaseDomain domain);

    /**
     * 发送网关
     * @param domain
     * @return
     */
    protected abstract GatewayResultFacade send(BaseDomain domain);

    /**
     * 执行结果转换
     * @param domain
     * @param result
     */
    protected abstract void result(BaseDomain domain,ResultFacade result);
}
